#include "Background.h"
#include <fstream>
#include <iostream>
#include "../Games/MyGame.h"

Background::Background(int maxFrequency, std::string name) :
		GameEntity(maxFrequency, name)
{
	origPosition.x = NULL;
	origPosition.y = NULL;
	origPosition.z = NULL;
	
	_directionState = DOWN;
}

Background::~Background()
{
}

void Background::draw()
{	
	SCALE scale = {3,3,3};
	GameEngine::Instance()->getRenderer()->drawPieceQuad("assets/background.raw\0", 2,2,2, this->getPosition(),this->getOrientation(), scale,512,512,this->getColor());
}

void Background::actualUpdate(unsigned long long timePassed)
{
	if(origPosition.x == NULL && origPosition.y == NULL && origPosition.z == NULL) {
		origPosition.x = getPosition().x;
		origPosition.y = getPosition().y;
		origPosition.z = getPosition().z;
	}
	POINT3D newPosition = {getPosition().x, getPosition().y, getPosition().z};

	switch(_directionState) {
		case LEFT: 
			newPosition.x--;
			break;
		case RIGHT: 
			newPosition.x++;
			break;
		case UP: 
			newPosition.y++;
			break;
		case DOWN: 
			newPosition.y -= 0.1f;
			break;
	}
	if(newPosition.y < -44.5) {
		newPosition.y = origPosition.y;
	}
	setPosition(newPosition);
	_directionState = DOWN;

}
void Background::onMouseScrolled(int xcoord, int ycoord, int distance){
}

void Background::reset(){}

void Background::onKeyPressed(int key){
}			//If a key is pressed, this function is called


void Background::onKeyReleased(int){}		//If a key is released, this function is called

void Background::onMouseMoved(int, int){}			//If a mouseIsMoved, this function is called
void Background::onMouseClicked(int, int){}			//If a mouseIsClicked, this function is called

int Background::getType() {
	return BACKGROUND;
}